# -*- ecoding: utf-8 -*-
# @ModuleName: redis_util
# @Author: wangwei 
# @Time: 2023/10/20 11:29
import redis


class RedisUtil:

    def __init__(self, host="82.156.74.26", port=6379,password='mtx',decode_responses=True):
        pool = redis.ConnectionPool(
            host=host, port=port,password=password,decode_responses=decode_responses
        )
        self.res=redis.Redis(connection_pool=pool)

    def get_value(self,key):
        # print(self.res.keys('*'))
        # for a in self.res.keys('*'):
        #     print(f"{a}的类型：{self.res.type(a)}")
        data_type=self.res.type(key)
        print(data_type)
        value=None
        if data_type=='string':
            value=self.res.get(key)
        elif data_type=='hash':
            value=self.res.hgetall(key)
        elif data_type=='list':
            value=self.res.lrange(key,0,-1)
        elif data_type=='set':
            value=self.res.smembers(key)
        elif data_type=='zset':
            value=self.res.zrange(key)
        return value

    def close(self):
        self.res.close()
# if __name__ == '__main__':
#     print(RedisUtil().get('name'))
#     RedisUtil().close()
